package com.ielts.activity.adapter;

import vn.com.baseapplication.BaseFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.ielts.IeltsConstant.PAGE;
import com.ielts.activity.R;
import com.ielts.fragment.AccountFragment;
import com.ielts.fragment.AllFragment;
import com.ielts.fragment.BuyedFragment;
import com.ielts.fragment.FanpageFragment;
import com.ielts.fragment.HelpFragment;
import com.viewpagerindicator.IconPagerAdapter;

public class MainAdapter extends FragmentPagerAdapter implements
		IconPagerAdapter {
	private static final String[] CONTENT = new String[] { "All",
			"Bought", "Account", "Fanpage", "Help" };
	private static final int[] ICONS = new int[] { R.drawable.tab_all,
			R.drawable.tab_buy, R.drawable.tab_account,
			R.drawable.tab_fanpage, R.drawable.tab_help };
	
	private static final int[] ICONS_SELECTED = ICONS;
	public BaseFragment allFrgmt,buyedFrgmt,accFrgmt,fanpageFrgmt,helpFrgmt;
	public MainAdapter(FragmentManager fm) {
		super(fm);
	}

	@Override
	public Fragment getItem(int position) {
		switch (PAGE.getPage(position)) {
		case ALL:
			if(allFrgmt==null || allFrgmt.getActivity()==null) allFrgmt = new AllFragment();
			return allFrgmt;
		case BUYED:
			if(buyedFrgmt==null || buyedFrgmt.getActivity()==null) buyedFrgmt = new BuyedFragment();
			return buyedFrgmt;
		case ACCOUNT:
			if(accFrgmt==null || accFrgmt.getActivity()==null) accFrgmt = new AccountFragment();
			return accFrgmt;
		case FANPAGE:
			if(fanpageFrgmt==null || fanpageFrgmt.getActivity()==null) fanpageFrgmt = new FanpageFragment();
			return fanpageFrgmt;
		case HELP:
			if(helpFrgmt==null || helpFrgmt.getActivity()==null) helpFrgmt = new HelpFragment();
			return helpFrgmt;
		}
		return null;
	}

	@Override
	public CharSequence getPageTitle(int position) {
		return CONTENT[position % CONTENT.length].toUpperCase();
	}

	@Override
	public int getIconResId(int index) {
		return ICONS[index];
	}
	
	@Override
	public int getIconResIdSelected(int index) {
		return ICONS_SELECTED[index];
	}
	
	@Override
	public int getBgRestId(int id) {
		return 0;
	}
	
	@Override
	public int getBgRestIdSelected(int id) {
//		return R.drawable.tab_bg_selected;
		return R.drawable.btn_charge_selected;
	}

	@Override
	public int getCount() {
		return CONTENT.length;
	}
}